package health.lm.com.home.presenter;

import android.view.View;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.List;

import health.lm.com.component_base.base.mvp.contract.XPresent;
import health.lm.com.component_base.popup.notice.NoticePopUtil;
import health.lm.com.home.activity.InformationsSearchActivity;
import health.lm.com.home.entity.ContentItemEntity;
import health.lm.com.home.entity.SugarEntity;
import health.lm.com.home.model.HomeModel;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.network.exception.ApiException;

/**
 * @author GQI
 * @description: 搜索
 * @date :2019-08-01 8:40
 */
public class InformationsSearchPresenter extends XPresent<InformationsSearchActivity> {
    public boolean isGet = true;

    public void getListData(String id,boolean isRefresh, Object layout, int page, int pageSize){
        HomeModel.getInstance().informationSearch(id, page, pageSize, new SimpleCallBack<List<ContentItemEntity>>() {
            @Override
            public void onSuccess(List<ContentItemEntity> list) {
                if(isRefresh){
                    ((SmartRefreshLayout)layout).finishRefresh(true);
                }
                if (hasV()) {
                    getV().getListDataSuccess(list);
                }
            }

            @Override
            public void onError(ApiException e) {
                super.onError(e);
                if(isRefresh){
                    ((SmartRefreshLayout)layout).finishRefresh(true);
                }
            }
        });
    }
    public void views(String id){
        HomeModel.getInstance().informationViews(id, new SimpleCallBack<Object>() {
            @Override
            public void onSuccess(Object o) {

            }
        });
    }
    public void getSugar(View view, String id){
        HomeModel.getInstance().getSugar(id, new SimpleCallBack<SugarEntity>() {
            @Override
            public void onSuccess(SugarEntity sugarEntity) {
                if (isGet){
                    isGet = false;
                    NoticePopUtil.getInstance().show(getV().mActivity,view,sugarEntity.getSugar(),"");
                }

            }
        });
    }
}
